/**
 * Copyright 2008 Matthew DeLambo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.delambo.drool.pooling;

import com.delambo.drool.interfaces.*;
import java.util.*;
import java.sql.*;

/**
 * Immutable and thread-safe Map of key/value pairs.
 * @author delambo
 * @param K type of key.
 * @param V type of value.
 */
public final class ImmutableMap_Impl<K, V extends Pool> 
        implements Map<K, V>, ImmutableMap<K, V> {
    
    private final Map<K, V> map; 
    
    public ImmutableMap_Impl(Map<K, V> map) {
        this.map = new HashMap<K, V>(map);
    }
    
    /**
     * Operation not permitted in order to maintain thread-safe immutability...
     */
    public final V put(K key, V value) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * Given a key, returns the mapped value.
     * @param key key to look up value.
     * @return value that matches key.
     */
    public final V get(Object key) {
        return map.get(key);
    }
    
    /**
     * Operation not permitted in order to maintain thread-safe immutability...
     */
    public final V remove(Object key) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * Returns the size of the map.
     * @return size of map.
     */
    public final int size() {
        return map.size();
    } 
    
    /**
     * Checks for the given key in the map.
     * @param key key to be checked.
     * @return true, if key exists; otherwise, false.
     */
    public final boolean containsKey(Object key) {
        return map.containsKey(key);
    }
    
    /**
     * Checks for the given value in the map.
     * @param value value to be checked for key.
     * @return true, if value exists; otherwise, false.
     */
    public final boolean containsValue(Object value) {
        return map.containsKey(value);
    } 
    
    /**
     * Returns a Set view of the mappings contained in this map.
     * @return entry set.
     */
    public final Set entrySet() {
        return map.entrySet();
    } 
    
    /**
     * Returns a Set view of the keys contained in this map.
     * @return key set.
     */
    public final Set keySet() {
        return map.keySet();
    } 
    
    /**
     * Returns a Collection view of the values contained in this map.
     * @return collection of mapped values.
     */
    public final Collection values() {
        return map.values();
    }
    
    /**
     * Operation not permitted in order to maintain thread-safe immutability...
     */
    public final void clear() {
        throw new UnsupportedOperationException();
    }
    
    /**
     * Operation not permitted in order to maintain thread-safe immutability...
     */
    public final void putAll(Map map) {
        throw new UnsupportedOperationException();
    }
    
    /**
     * Returns true if this map contains no key-value mappings.
     * @return true, if no mappings; otherwise, false.
     */
    public final boolean isEmpty() {
        return map.isEmpty();
    } 
}
